using System;
using System.Collections.Generic;

namespace OffsetPath
{
    public static class ClassAtAs
    {
        private static double a = 0.1;
        private static double b = ClassK.e;
        private static double c = 0.0001;

        public static double MethodA()
        {
            return c;
        }

        public static bool MethodA(ClassO_List_LineArco A_0)
        {
            return (MethodB(A_0) < 0.0);
        }

        public static void MethodA(double A_0)
        {
            c = Math.Abs(A_0);
        }

        public static PuntoDueD MethodA(ForseLineaClassA A_0, ForseLineaClassA A_1)
        {
            var presuntoPuntoSkeleton =MethodA(A_0.a, A_0.b, A_1.a, A_1.b);

            return presuntoPuntoSkeleton;
        }

        public static double MethodA(ForseLineaClassA A_0, PuntoDueD A_1)
        {
            double num = Math.Abs((double) ((A_0.b.a * (A_0.a.Y - A_1.Y)) - (A_0.b.b * (A_0.a.X - A_1.X))));
            double num2 = Math.Sqrt((A_0.b.a * A_0.b.a) + (A_0.b.b * A_0.b.b));
            double d = 0.0;
            d = num / num2;
            if (!double.IsInfinity(d) && !double.IsNaN(d))
            {
                return d;
            }
            return 0.0;
        }

        public static bool MethodA(ClasseBaseLineaArcoClassAf A_0, PuntoDueD A_1)
        {
            ForseLineaClassA a = A_0 as ForseLineaClassA;
            if (a != null)
            {
                a.d(A_1);
                return true;
            }
            ForseArco2ClassQ classQ = A_0 as ForseArco2ClassQ;
            if (classQ == null)
            {
                throw new ArgumentException("linebase");
            }
            PuntoDueD puntoDueD = classQ.e();
            ForseLineaClassA a2 = new ForseLineaClassA(classQ.h(), A_1);
            ForseArco2ClassQ q2 = new ForseArco2ClassQ(a2, classQ.d, a2.MethodB(puntoDueD), classQ.b);
            if (!q2.MethodD())
            {
                return false;
            }
            classQ.MethodA(q2);
            return true;
        }

        public static void MethodA(ContenitoreLivello A_0, List<OffsetProfilo2D> A_1)
        {
            for (int i = 0; (i < A_0.Count) && (A_1.Count > 0); i++)
            {
                PolygonalShape polygonalShape = A_0[i];
                for (int j = 0; j < A_1.Count; j++)
                {
                    List<PolygonalShape> list = new List<PolygonalShape>();
                    if (MethodA(polygonalShape, A_1[j], list) && (list.Count > 0))
                    {
                        A_1.RemoveAt(j);
                        j--;
                        for (int k = list.Count - 1; k >= 0; k--)
                        {
                            A_0.Insert(i + 1, list[k]);
                        }
                        A_0.RemoveAt(i);
                        i--;
                        break;
                    }
                }
            }
        }

        public static ClassAtPuntoIncrementale MethodA(ClassAtPuntoIncrementale A_0, ClassAtPuntoIncrementale A_1)
        {
            double num = A_0.c();
            double num2 = A_1.c();
            return new ClassAtPuntoIncrementale((num * A_1.a) + (num2 * A_0.a), (num * A_1.b) + (num2 * A_0.b));
        }

        public static bool MethodA(ForseLineaClassA A_0, ForseLineaClassA A_1, PuntoDueD A_2)
        {
            double num;
            double num2;
            if (!MethodA(A_0, A_1, out num, out num2))
            {
                return false;
            }
            A_2.MethodA(num, num2);
            return true;
        }

        public static bool MethodA(ForseLineaClassA A_0, PuntoDueD A_1, bool A_2 = false)
        {
            double num = (A_0.b.b * (A_1.X - A_0.a.X)) - (A_0.b.a * (A_1.Y - A_0.a.Y));
            if (A_2)
            {
                return (num >= 0.0);
            }
            return (num > 0.0);
        }

        public static bool MethodA(ClasseBaseLineaArcoClassAf A_0, bool A_1, double A_2)
        {
            ForseLineaClassA a = A_0 as ForseLineaClassA;
            if (a != null)
            {
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(a.b);
                if (A_1)
                {
                    classAt.e();
                }
                else
                {
                    classAt.MethodB();
                }
                classAt.MethodA(A_2);
                a.p(classAt);
                return true;
            }
            ForseArco2ClassQ classQ = A_0 as ForseArco2ClassQ;
            if (classQ == null)
            {
                throw new ArgumentException("linebase");
            }
            PuntoDueD puntoDueD = classQ.e();
            double d = classQ.d;
            ClassAtPuntoIncrementale at2 = new ClassAtPuntoIncrementale(puntoDueD, classQ.h());
            ClassAtPuntoIncrementale at3 = new ClassAtPuntoIncrementale(puntoDueD, classQ.i());
            if (A_1 == !classQ.b)
            {
                d += A_2;
            }
            else
            {
                d -= A_2;
            }
            if (d < MethodC())
            {
                return false;
            }
            at2.MethodA(d);
            at3.MethodA(d);
            PuntoDueD x2 = new PuntoDueD(puntoDueD);
            x2.p(at2);
            PuntoDueD x3 = new PuntoDueD(puntoDueD);
            x3.p(at3);
            d = Math.Max(d, x2.MethodC(x3) / 2.0);
            classQ.MethodA(x2, x3, d, classQ.c, classQ.b);
            return true;
        }

        public static bool MethodA(PolygonalShape A_0, OffsetProfilo2D A_1, List<PolygonalShape> A_2)
        {
            A_2.Clear();
            if (A_1.GetListaLineaArco().Count == 0)
            {
                return false;
            }
            if (!A_0.GetExternPolygon().MethodC(A_1) && !A_0.GetExternPolygon().d(A_1.GetListaLineaArco()[0].h()))
            {
                return false;
            }
            var classAi = new PolygonalShape(A_1);
            var ag = new ClassAg {
                               c = ClassAg.EnumA.c
                           };
            A_0.MethodA1(classAi, A_2, false, true, ag);
            return true;
        }

        public static void MethodA(ForseArco2ClassQ A_0, int A_1, List<ClasseBaseLineaArcoClassAf> A_2)
        {
            if (A_1 <= 1)
            {
                A_2.Add(A_0.MethodA());
            }
            else
            {
                PuntoDueD puntoDueD = A_0.e();
                PuntoDueD x2 = A_0.h();
                PuntoDueD x3 = A_0.i();
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(puntoDueD, x2);
                ClassAtPuntoIncrementale at2 = new ClassAtPuntoIncrementale(puntoDueD, x3);
                double num = 0.0;
                if (A_0.b)
                {
                    num = classAt.d(at2);
                }
                else
                {
                    num = classAt.c(at2);
                }
                double num2 = num / ((double) A_1);
                double num3 = MethodC() / A_0.d;
                num2 = Math.Max(num2, num3);
                List<PuntoDueD> list = new List<PuntoDueD>();
                ClassAtPuntoIncrementale at3 = new ClassAtPuntoIncrementale(classAt);
                for (double i = num2; i < (num - num3); i += num2)
                {
                    if (A_0.b)
                    {
                        at3.c(num2);
                    }
                    else
                    {
                        at3.MethodB(num2);
                    }
                    PuntoDueD item = new PuntoDueD(puntoDueD);
                    item.p(at3);
                    list.Add(item);
                }
                A_0.j(list, A_2);
            }
        }

        public static bool MethodA(ForseLineaClassA A_0, ForseLineaClassA A_1, out double A_2, out double A_3)
        {
            double a = A_0.a.X;
            double b = A_0.a.Y;
            double num3 = a + A_0.b.a;
            double num4 = b + A_0.b.b;
            double num5 = A_1.a.X;
            double num6 = A_1.a.Y;
            double num7 = num5 + A_1.b.a;
            double num8 = num6 + A_1.b.b;
            double d = ((num7 - num5) * (b - num6)) - ((num8 - num6) * (a - num5));
            double num10 = ((num8 - num6) * (num3 - a)) - ((num7 - num5) * (num4 - b));
            if (Math.Abs(num10) <= ClassAtAs.MethodB())
            {
                A_2 = 0.0;
                A_3 = 0.0;
                return false;
            }
            d /= num10;
            if (double.IsInfinity(d) || double.IsNaN(d))
            {
                A_2 = 0.0;
                A_3 = 0.0;
                return false;
            }
            A_2 = a + (d * A_0.b.a);
            A_3 = b + (d * A_0.b.b);
            if ((!double.IsInfinity(A_2) && !double.IsNaN(A_2)) && (!double.IsInfinity(A_3) && !double.IsNaN(A_3)))
            {
                return true;
            }
            A_2 = 0.0;
            A_3 = 0.0;
            return false;
        }

        public static void MethodA(ClassO_List_LineArco A_0, bool A_1, ClassV A_2, ClassV A_3)
        {
            List<PuntoDueD> list = new List<PuntoDueD>();
            List<int> list2 = new List<int>();
            List<int> list3 = new List<int>();
            A_0.MethodA(list, list2, list3);
            if (list.Count == 0)
            {
                if (A_1 == MethodA(A_0))
                {
                    A_2.Add(A_0);
                }
                else
                {
                    A_3.Add(A_0);
                }
            }
            else
            {
                ClassV classV = new ClassV();
                MethodA(A_0, list[0], list2[0], list3[0], classV);
                foreach (ClassO_List_LineArco o in classV)
                {
                    MethodA(o, A_1, A_2, A_3);
                }
            }
        }

        public static PuntoDueD MethodA(PuntoDueD A_0, ClassAtPuntoIncrementale A_1, PuntoDueD A_2, ClassAtPuntoIncrementale A_3)
        {
            double a = A_0.X;
            double b = A_0.Y;
            double num3 = a + A_1.a;
            double num4 = b + A_1.b;
            double num5 = A_2.X;
            double num6 = A_2.Y;
            double num7 = num5 + A_3.a;
            double num8 = num6 + A_3.b;
            double d = ((num7 - num5) * (b - num6)) - ((num8 - num6) * (a - num5));
            double num10 = ((num8 - num6) * (num3 - a)) - ((num7 - num5) * (num4 - b));
            if (Math.Abs(num10) <= ClassAtAs.MethodB())
            {
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(A_0, A_2);
                if (Math.Abs(classAt.g(A_1)) <= ClassAtAs.MethodB())
                {
                    if (A_1.MethodB(A_3) <= 0.0)
                    {
                        return new PuntoDueD((a + num5) / 2.0, (b + num6) / 2.0);
                    }
                    if (classAt.MethodB(A_1) > 0.0)
                    {
                        return new PuntoDueD(A_2);
                    }
                    return new PuntoDueD(A_0);
                }
            }
            d /= num10;
            if (((d >= 0.0) && !double.IsInfinity(d)) && !double.IsNaN(d))
            {
                double num11 = a + (d * A_1.a);
                double num12 = b + (d * A_1.b);
                if ((double.IsInfinity(num11) || double.IsNaN(num11)) || (double.IsInfinity(num12) || double.IsNaN(num12)))
                {
                    return null;
                }
                if ((((num11 - num5) * A_3.a) > -ClassAtAs.MethodB()) && (((num12 - num6) * A_3.b) > -ClassAtAs.MethodB()))
                {
                    return new PuntoDueD(num11, num12);
                }
            }
            return null;
        }

        public static void MethodA(ClassO_List_LineArco A_0, PuntoDueD A_1, int A_2, int A_3, ClassV A_4)
        {
            if (((A_2 == A_3) || (A_2 < 0)) || (((A_3 < 0) || (A_2 >= A_0.Count)) || (A_3 >= A_0.Count)))
            {
                throw new ArgumentException();
            }
            A_4.Clear();
            ClassO_List_LineArco item = new ClassO_List_LineArco();
            int num = A_3;
            while (true)
            {
                if (num >= A_0.Count)
                {
                    num = 0;
                }
                if (num == A_3)
                {
                    ClasseBaseLineaArcoClassAf af = A_0[A_3].MethodA();
                    MethodB(af, A_1);
                    item.Add(af);
                }
                else
                {
                    if (num == A_2)
                    {
                        var af2 = A_0[A_2].MethodA();
                        MethodA(af2, A_1);
                        item.Add(af2);
                        break;
                    }
                    item.Add(A_0[num]);
                }
                num++;
            }
            if (item.Count >= 3)
            {
                A_4.Add(item);
            }
            ClassO_List_LineArco o2 = new ClassO_List_LineArco();
            int num2 = A_2;
            while (true)
            {
                if (num2 >= A_0.Count)
                {
                    num2 = 0;
                }
                if (num2 == A_2)
                {
                    var af3 = A_0[A_2].MethodA();
                    MethodB(af3, A_1);
                    o2.Add(af3);
                }
                else
                {
                    if (num2 == A_3)
                    {
                       var af4 = A_0[A_3].MethodA();
                        MethodA(af4, A_1);
                        o2.Add(af4);
                        break;
                    }
                    o2.Add(A_0[num2]);
                }
                num2++;
            }
            if (o2.Count >= 3)
            {
                A_4.Add(o2);
            }
        }

        public static double MethodB()
        {
            return b;
        }

        public static double MethodB(ClassO_List_LineArco A_0)
        {
            double num = 0.0;
            for (int i = 0; i < A_0.Count; i++)
            {
                PuntoDueD puntoDueD = A_0[i].h();
                PuntoDueD x2 = A_0[i].i();
                num += (puntoDueD.X * x2.Y) - (x2.X * puntoDueD.Y);
            }
            num /= 2.0;
            for (int j = 0; j < A_0.Count; j++)
            {
                if (A_0[j] is ForseArco2ClassQ)
                {
                    ForseArco2ClassQ classQ = A_0[j] as ForseArco2ClassQ;
                    var an = new ClassAn(classQ);
                    num += an.q();
                }
            }
            return num;
        }

        public static void MethodB(double A_0)
        {
            b = Math.Abs(A_0);
        }

        public static PuntoDueD MethodB(ForseLineaClassA A_0, ForseLineaClassA A_1)
        {
            double num;
            double num2;
            if (!MethodA(A_0, A_1, out num, out num2))
            {
                return null;
            }
            var l = A_0.a.AngleStart;
            // qui si comporta bene
            return new PuntoDueD(num, num2,A_0.a.AngleStart);
        }

        public static bool MethodB(ClasseBaseLineaArcoClassAf A_0, PuntoDueD A_1)
        {
            var a = A_0 as ForseLineaClassA;
            if (a != null)
            {
                a.MethodA(A_1);
                return true;
            }
            ForseArco2ClassQ classQ = A_0 as ForseArco2ClassQ;
            if (classQ == null)
            {
                throw new ArgumentException("linebase");
            }
            PuntoDueD puntoDueD = classQ.e();
            var a2 = new ForseLineaClassA(A_1, classQ.i());
            ForseArco2ClassQ q2 = new ForseArco2ClassQ(a2, classQ.d, a2.MethodB(puntoDueD), classQ.b);
            if (!q2.MethodD())
            {
                return false;
            }
            classQ.MethodA(q2);
            return true;
        }

        public static double MethodC()
        {
            return a;
        }

        public static void MethodC(double A_0)
        {
            a = Math.Abs(A_0);
        }
    }
}

